home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / WIZUNZIP.C < prev    next >
C/C++ Source or Header  |  1993-07-03  |  12KB  |  269 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: WizUnZip.c
  4.  
  5.     PURPOSE:  Windows Info-ZIP Unzip, an Unzipper for Windows
  6.     FUNCTIONS:
  7.  
  8.         WinMain() - calls initialization function, processes message loop
  9.         WizUnzipInit() - initializes window data and registers window
  10.         WizUnzipWndProc() - processes messages
  11.         About() - processes messages for "About" dialog box
  12.  
  13.     AUTHOR: Robert A. Heath,  157 Chartwell Rd. Columbia, SC 29210
  14.     I place this source module, WizUnzip.c, in the public domain.  Use it as you will.
  15. ****************************************************************************/
  16.  
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <time.h>                
  20. #include <string.h>             
  21. #include "wizunzip.h"
  22.  
  23.  
  24. static char __based(__segname("STRINGS_TEXT")) szFirstUse[] = "FirstUse"; /* first use keyword in WIN.INI */
  25. char __based(__segname("STRINGS_TEXT")) szDefaultUnzipToDir[] = "DefaultUnzipToDir";
  26. char __based(__segname("STRINGS_TEXT")) szFormatKey[] = "Format";       /* Format keyword in WIN.INI        */
  27. char __based(__segname("STRINGS_TEXT")) szOverwriteKey[] = "Overwrite"; /* Overwrite keyword in WIN.INI     */
  28. char __based(__segname("STRINGS_TEXT")) szTranslateKey[] = "Translate"; /* Translate keyword in WIN.INI     */
  29. char __based(__segname("STRINGS_TEXT")) szLBSelectionKey[] = "LBSelection"; /* LBSelection keyword in WIN.INI */
  30. char __based(__segname("STRINGS_TEXT")) szRecreateDirsKey[] = "Re-createDirs"; /* re-create directory structure WIN.INI keyword             */
  31. char __based(__segname("STRINGS_TEXT")) szUnzipToZipDirKey[] = "UnzipToZipDir"; /* unzip to .ZIP dir WIN.INI keyword */
  32. char __based(__segname("STRINGS_TEXT")) szHideStatus[] = "HideStatusWindow";
  33. char __based(__segname("STRINGS_TEXT")) szAutoClearStatusKey[] = "AutoClearStatus";
  34. char __based(__segname("STRINGS_TEXT")) szHelpFileName[] = "WIZUNZIP.HLP";
  35. char __based(__segname("STRINGS_TEXT")) szWizUnzipIniFile[] = "WIZUNZIP.INI";
  36. char __based(__segname("STRINGS_TEXT")) szYes[] = "yes";
  37. char __based(__segname("STRINGS_TEXT")) szNo[] = "no";
  38.  
  39. /* File and Path Name variables */
  40. char __based(__segname("STRINGS_TEXT")) szAppName[] = "WizUnZip";       /* application title        */
  41. char __based(__segname("STRINGS_TEXT")) szStatusClass[] = "MsgWndw";/* status window class  */
  42.                                                 
  43. /* Values for listbox selection WIN.INI keyword
  44.  */
  45. char * LBSelectionTable[] = {
  46.     "extract", "display", "test" 
  47. };
  48. #define LBSELECTIONTABLE_ENTRIES (sizeof(LBSelectionTable)/sizeof(char *))
  49.  
  50. HANDLE hInst;               /* current instance */
  51. HMENU  hMenu;               /* main menu handle */
  52. HANDLE hAccTable;
  53.  
  54. HANDLE hHourGlass;          /* handle to hourglass cursor        */
  55. HANDLE hSaveCursor;         /* current cursor handle         */
  56. HANDLE hHelpCursor;         /* help cursor                      */
  57. HANDLE hFixedFont;          /* handle to fixed font             */
  58. HANDLE hOldFont;            /* handle to old font               */
  59.  
  60. int hFile;                /* file handle             */
  61. HWND hWndMain;        /* the main window handle.                */
  62. HWND hWndList;            /* list box handle        */
  63. HWND hWndStatus;        /* status   (a.k.a. Messages) window */
  64. HWND hExtract;          /* extract button               */
  65. HWND hDisplay;          /*display button                */
  66. HWND hTest;             /* test button              */
  67. HWND hShowComment;          /* show comment button          */
  68.  
  69. UF  uf;
  70.  
  71.  
  72. WORD wLBSelection = IDM_LB_DISPLAY; /* default listbox selection action */
  73. WORD wWindowSelection = IDM_SPLIT; /* window selection: listbox, status, both    */
  74.  
  75.  
  76. HBRUSH hBrush ;         /* brush for  standard window backgrounds  */
  77.  
  78. LPUMB   lpumb;
  79. HANDLE  hStrings;
  80.  
  81. int ofretval;       /* return value from initial open if filename given */
  82.  
  83. WORD cZippedFiles;      /* total personal records in file   */
  84. WORD cListBoxLines; /* max list box lines showing on screen */
  85. WORD cLinesMessageWin; /* max visible lines on message window  */
  86. WORD cchComment;            /* length of comment in .ZIP file   */
  87.  
  88.  
  89. /* Forward References */
  90. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  91. long FAR PASCAL WizUnzipWndProc(HWND, WORD, WORD, LONG);
  92.  
  93.  
  94. /****************************************************************************
  95.  
  96.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  97.  
  98.     PURPOSE: calls initialization function, processes message loop
  99.  
  100.     COMMENTS:
  101.  
  102.         This will initialize the window class if it is the first time this
  103.         application is run.  It then creates the window, and processes the
  104.         message loop until a WM_QUIT message is received.  It exits the
  105.         application by returning the value passed by the PostQuitMessage.
  106.  
  107. ****************************************************************************/
  108.  
  109. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  110. HANDLE hInstance;         /* current instance             */
  111. HANDLE hPrevInstance;     /* previous instance            */
  112. LPSTR lpCmdLine;          /* command line                 */
  113. int nCmdShow;             /* show-window type (open/icon) */
  114. {
  115.     int i;
  116.     BOOL fFirstUse;            /* first use if TRUE            */
  117.  
  118.  
  119.     if (!hPrevInstance)                 /* Has application been initialized? */
  120.         if (!WizUnzipInit(hInstance))
  121.             return 0;              /* Exits if unable to initialize     */
  122.  
  123.  
  124.     hStrings = GlobalAlloc( GPTR, (DWORD)sizeof(UMB));
  125.     if ( !hStrings )
  126.         return 0;
  127.  
  128.     lpumb = (LPUMB)GlobalLock( hStrings );
  129.     if ( !lpumb )
  130.     {
  131.         GlobalFree( hStrings );
  132.         return 0;
  133.     }
  134.  
  135.     uf.fCanDragDrop = FALSE;
  136.     if (hHourGlass = GetModuleHandle("SHELL"))
  137.     {
  138.         if (GetProcAddress(hHourGlass, "DragAcceptFiles" ))
  139.             uf.fCanDragDrop = TRUE;
  140.     }
  141.     
  142.     if (_fstrlen(lpCmdLine))            /* if filename passed on start-up   */
  143.     {
  144.         if ((ofretval = OpenFile(lpCmdLine, &lpumb->of, OF_EXIST)) >= 0)
  145.             lstrcpy(lpumb->szFileName, lpumb->of.szPathName); /* save file name */
  146.  
  147.     }
  148.  
  149.     /* If first time using WizUnzip 2.0, migrate any of earlier WizUnZip options from WIN.INI 
  150.      * to WIZUNZIP.INI.
  151.      */
  152.     GetPrivateProfileString(szAppName, szFirstUse, szYes, lpumb->szBuffer, 256, szWizUnzipIniFile);
  153.     if (fFirstUse = !lstrcmpi(lpumb->szBuffer, szYes)) /* first time used as WizUnZip 2.0    */
  154.     {
  155.  
  156.            GetProfileString(szAppName, szRecreateDirsKey, szYes, lpumb->szBuffer, OPTIONS_BUFFER_LEN);
  157.         WritePrivateProfileString(szAppName, szRecreateDirsKey, lpumb->szBuffer, szWizUnzipIniFile);
  158.  
  159.         /* Don't propagate translate option. Its meaning has changed. Use default: No    */
  160.  
  161.         GetProfileString(szAppName, szOverwriteKey, szNo, lpumb->szBuffer, OPTIONS_BUFFER_LEN);
  162.         WritePrivateProfileString(szAppName, szOverwriteKey, lpumb->szBuffer, szWizUnzipIniFile);
  163.  
  164.         GetProfileString(szAppName, szFormatKey, "long", lpumb->szBuffer, OPTIONS_BUFFER_LEN);
  165.         WritePrivateProfileString(szAppName, szFormatKey, lpumb->szBuffer, szWizUnzipIniFile);
  166.  
  167.         GetProfileString(szAppName, szUnzipToZipDirKey, szNo, lpumb->szBuffer, OPTIONS_BUFFER_LEN);
  168.         WritePrivateProfileString(szAppName, szUnzipToZipDirKey, lpumb->szBuffer, szWizUnzipIniFile);
  169.     
  170.         GetProfileString(szAppName, szLBSelectionKey, "display", lpumb->szBuffer, OPTIONS_BUFFER_LEN);
  171.         WritePrivateProfileString(szAppName, szLBSelectionKey, lpumb->szBuffer, szWizUnzipIniFile);
  172.  
  173.          MigrateSoundOptions();    /* Translate former beep option to new sound option    */
  174.  
  175.         WriteProfileString(szAppName, NULL, NULL); /* delete [wizunzip] section of WIN.INI file */
  176.  
  177.         /* Flag that this is no longer the first time.                                        */
  178.         WritePrivateProfileString(szAppName, szFirstUse, szNo, szWizUnzipIniFile);
  179.  
  180.         /* After first use, all options come out of WIZUNZIP.INI file                        */
  181.     }
  182.  
  183.     /* Get initial Re-create dirs format */
  184.     GetPrivateProfileString(szAppName, szRecreateDirsKey, szYes, lpumb->szBuffer, OPTIONS_BUFFER_LEN, szWizUnzipIniFile);
  185.     uf.fRecreate